﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace eu.h8me.Parsing.LexerLib2 {

    public class Demo {

        // Build helper.
        public static void BuildTNFA() {
            TNFA rv = ( new TNFA(new TNFAIntTag(1, true)) & ( new TNFA(new CharRange('0', '9')).ZeroOrMore() & new TNFA(new CharRange('/')) ).OneOrMore() & new TNFA(new TNFAIntTag(2, true)) | new TNFA(new CharRange('5', '9')).Repeat(5, 5) ) & new TNFA(new CharRange('0', '9')).OneOrMore() & new TNFA(new CharRange('/'));
            TDFA test = new TDFA(new List<RegEx>() { new RegEx(rv) });

            foreach( object init in test.Initializers )
                Console.WriteLine("Init: {0},0", init);
            foreach( KeyValuePair<int, List<TDFATransition>> state in test.States ) {
                Console.WriteLine("State: {0}", state.Key);
                List<TDFAMatch> matches;
                if( test.Matchers.TryGetValue(state.Key, out matches) ) {
                    foreach( TDFAMatch match in matches ) {
                        Console.WriteLine("Match: {0}", match.RegEx);
                        foreach( KeyValuePair<ITNFATag, int> tag in match.Tags )
                            Console.WriteLine("Use: {0} -> {0},{1}", tag.Key, tag.Value);
                    }
                }

                // Display state.
                foreach( TDFATransition trans in state.Value ) {
                    Console.WriteLine("Match: {0}-{1}", trans.Start, trans.Stop);
                    foreach( KeyValuePair<ITNFATag, int> create in trans.CreateTagIndex )
                        Console.WriteLine("Create: {0},{1}", create.Key, create.Value);
                    foreach( KeyValuePair<ITNFATag, SortedDictionary<int, int>> adapt in trans.AdaptTagIndex )
                        foreach( KeyValuePair<int, int> a in adapt.Value )
                            Console.WriteLine("Adapt: {0},{1} -> {0},{2}", adapt.Key, a.Key, a.Value);
                    Console.WriteLine("Goto: {0}", trans.Target);
                }

                Console.WriteLine();
            }
        }

    }

}
